/**
 * 评估表管理初始化
 */
var EvalDic = {
    id: "EvalDicTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
EvalDic.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '代码', field: 'code', width: 100, align: 'left', valign: 'middle', sortable: true},
        {title: '描述', field: 'description', width: 200, align: 'left', valign: 'middle', sortable: true},
        {title: 'cdss名称', field: 'cdssEvalName', width: 200, align: 'left', valign: 'middle', sortable: true},
        {title: '分数级别信息', field: 'dicLevelInfo', width: 200, align: 'left', valign: 'middle', sortable: true,formatter:function(value,row,index){
                if(value==null||value=="") return "";
                var info = "";
                $.each(value,function(i,d){
                    info += d.result+":["+d.lowerLimit+","+d.upperLimit+"];";
                });
                return info;
            }},
        {title: '分类', field: 'type', width: 50, align: 'center', valign: 'middle', sortable: true,formatter:function(value,row,index) {
            if (value == 1) {
                return "<span class='label label-success'>评估</span>";
            } else {
                return "<span class='label label-primary'>评价</span>";
            }
        }},
        {title: '展示类型', field: 'showStyle', width: 80, align: 'center', valign: 'middle', sortable: true,formatter:function(value,row,index) {
                if (value == 1) {
                    return "<span class='label label-success'>竖分</span>";
                } else if(value == 2) {
                    return "<span class='label label-info'>横分</span>";
                } else {
                    return "<span class='label label-primary'>横分独表</span>";
                }
            }},
        {title: '状态', field: 'isActive', width: 50, align: 'center', valign: 'middle', sortable: true,formatter:function(value,row,index){
        	if(value==1){
                return "<span class='label label-success'>启用</span>";
        	}else{
                return "<span class='label label-warning'>停用</span>";
        	}
        }},
        {title: '条目详细',width: 80, field: 'id', align: 'center', valign: 'middle', formatter:function(value,row,index){
        	return "<a onclick='getItemDetail(&apos;"+row.id+"&apos;)'><img style='width:18px;height:18px;'src='../static/common/img/detail.png'></a>";
        	}
        }
    ];
};

/**
 * 条目详细
 */
function getItemDetail(asmtId){
	var href = Sys.backendPath + "/sdc/evaldicitem/"+asmtId;
	Sys.addTabPage($.trim("字典条目详细"), href,true);
}

/**
 * 预览
 */
EvalDic.viewPdfModel = function (dicCode){
	var index = layer.open({
		type: 1,
		title: dicCode,
		area: ['800px', '100%'], //宽高
		fix: false, //不固定
		maxmin: true,
		content: '<iframe src="'+Sys.backendPath+'/static/evalform/'+dicCode+'.pdf" width="100%" height="100%"></iframe>'
		});
	layer.full(index);
	this.layerIndex = index;
};


/**
 * 检查是否选中
 */
EvalDic.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        EvalDic.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加评估表
 */
EvalDic.openAddEvalDic = function () {
    var index = layer.open({
        type: 2,
        title: '添加评估表',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Sys.backendPath + '/sdc/evaldic/to_add'
    });
    this.layerIndex = index;
};

/**
 * 修改评估表详情
 */
EvalDic.openEvalDicDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '评估表详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Sys.backendPath + '/sdc/evaldic/to_update/' + EvalDic.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除评估表
 */
EvalDic.del = function () {
    if (this.check()) {
        var operation = function(){
	        var ajax = new $ax(Sys.backendPath + "/sdc/evaldic/delete", function (data) {
	        	if(data.code==300){
	        		Sys.error(data.message);
	        	}else{
	        		Sys.success("删除成功!");
	        		EvalDic.table.refresh();
	        	}
	        }, function (data) {
	            Sys.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("sdcBaseAssessmentId",EvalDic.seItem.id);
	        ajax.start();
	    };
	    Sys.confirm("是否删除评估表?",operation);
    }
};

/**
 * 查询评估表列表
 */
EvalDic.search = function () {
    var queryData = {};
    queryData['description'] = $("#dicDesc").val();
    queryData['code'] = $("#dicCode").val();
    EvalDic.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = EvalDic.initColumn();
    var table = new BSTable(EvalDic.id, Sys.backendPath + "/sdc/evaldic/list", defaultColunms);
    table.setPaginationType("server");
    table.setPageSize(15);
    EvalDic.table = table.init();
});
